import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/16 10:05
 * @description 差分数组
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[][] trips = {{3,2,7},{3,7,9},{8,3,9}};
        solution.carPooling(trips, 11);
    }
    public boolean carPooling(int[][] trips, int capacity) {
        int[] diff = new int[1002];
        for (int[] trip: trips) {
            diff[trip[1]] += trip[0];
            diff[trip[2]] -= trip[0];
        }
        int cur = 0;
        for (int i = 0; i < 1002; i++) {
            cur += diff[i];
            if (cur > capacity) {
                return false;
            }
        }
        return true;
    }
}
